/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.swt.mto.thithu.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.util.PortalUtil;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import com.swt.mto.thithu.model.Result;
import com.swt.mto.thithu.model.ResultModel;

import java.io.Serializable;

import java.sql.Types;

import java.util.HashMap;
import java.util.Map;

/**
 * The base model implementation for the Result service. Represents a row in the &quot;mto_thithu_Result&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.swt.mto.thithu.model.ResultModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link ResultImpl}.
 * </p>
 *
 * @author tuan.nguyen
 * @see ResultImpl
 * @see com.swt.mto.thithu.model.Result
 * @see com.swt.mto.thithu.model.ResultModel
 * @generated
 */
public class ResultModelImpl extends BaseModelImpl<Result>
	implements ResultModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a result model instance should use the {@link com.swt.mto.thithu.model.Result} interface instead.
	 */
	public static final String TABLE_NAME = "mto_thithu_Result";
	public static final Object[][] TABLE_COLUMNS = {
			{ "resultId", Types.BIGINT },
			{ "quizId", Types.BIGINT },
			{ "userId", Types.BIGINT },
			{ "questionId", Types.BIGINT },
			{ "userName", Types.VARCHAR },
			{ "userChoice", Types.VARCHAR },
			{ "correct", Types.VARCHAR },
			{ "score", Types.INTEGER }
		};
	public static final String TABLE_SQL_CREATE = "create table mto_thithu_Result (resultId LONG not null primary key,quizId LONG,userId LONG,questionId LONG,userName VARCHAR(75) null,userChoice VARCHAR(75) null,correct VARCHAR(75) null,score INTEGER)";
	public static final String TABLE_SQL_DROP = "drop table mto_thithu_Result";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.swt.mto.thithu.model.Result"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.swt.mto.thithu.model.Result"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = false;
	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.swt.mto.thithu.model.Result"));

	public ResultModelImpl() {
	}

	public long getPrimaryKey() {
		return _resultId;
	}

	public void setPrimaryKey(long primaryKey) {
		setResultId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_resultId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return Result.class;
	}

	public String getModelClassName() {
		return Result.class.getName();
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("resultId", getResultId());
		attributes.put("quizId", getQuizId());
		attributes.put("userId", getUserId());
		attributes.put("questionId", getQuestionId());
		attributes.put("userName", getUserName());
		attributes.put("userChoice", getUserChoice());
		attributes.put("correct", getCorrect());
		attributes.put("score", getScore());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long resultId = (Long)attributes.get("resultId");

		if (resultId != null) {
			setResultId(resultId);
		}

		Long quizId = (Long)attributes.get("quizId");

		if (quizId != null) {
			setQuizId(quizId);
		}

		Long userId = (Long)attributes.get("userId");

		if (userId != null) {
			setUserId(userId);
		}

		Long questionId = (Long)attributes.get("questionId");

		if (questionId != null) {
			setQuestionId(questionId);
		}

		String userName = (String)attributes.get("userName");

		if (userName != null) {
			setUserName(userName);
		}

		String userChoice = (String)attributes.get("userChoice");

		if (userChoice != null) {
			setUserChoice(userChoice);
		}

		String correct = (String)attributes.get("correct");

		if (correct != null) {
			setCorrect(correct);
		}

		Integer score = (Integer)attributes.get("score");

		if (score != null) {
			setScore(score);
		}
	}

	public long getResultId() {
		return _resultId;
	}

	public void setResultId(long resultId) {
		_resultId = resultId;
	}

	public long getQuizId() {
		return _quizId;
	}

	public void setQuizId(long quizId) {
		_quizId = quizId;
	}

	public long getUserId() {
		return _userId;
	}

	public void setUserId(long userId) {
		_userId = userId;
	}

	public String getUserUuid() throws SystemException {
		return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
	}

	public void setUserUuid(String userUuid) {
		_userUuid = userUuid;
	}

	public long getQuestionId() {
		return _questionId;
	}

	public void setQuestionId(long questionId) {
		_questionId = questionId;
	}

	public String getUserName() {
		if (_userName == null) {
			return StringPool.BLANK;
		}
		else {
			return _userName;
		}
	}

	public void setUserName(String userName) {
		_userName = userName;
	}

	public String getUserChoice() {
		if (_userChoice == null) {
			return StringPool.BLANK;
		}
		else {
			return _userChoice;
		}
	}

	public void setUserChoice(String userChoice) {
		_userChoice = userChoice;
	}

	public String getCorrect() {
		if (_correct == null) {
			return StringPool.BLANK;
		}
		else {
			return _correct;
		}
	}

	public void setCorrect(String correct) {
		_correct = correct;
	}

	public int getScore() {
		return _score;
	}

	public void setScore(int score) {
		_score = score;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
			Result.class.getName(), getPrimaryKey());
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		ExpandoBridge expandoBridge = getExpandoBridge();

		expandoBridge.setAttributes(serviceContext);
	}

	@Override
	public Result toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (Result)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public Object clone() {
		ResultImpl resultImpl = new ResultImpl();

		resultImpl.setResultId(getResultId());
		resultImpl.setQuizId(getQuizId());
		resultImpl.setUserId(getUserId());
		resultImpl.setQuestionId(getQuestionId());
		resultImpl.setUserName(getUserName());
		resultImpl.setUserChoice(getUserChoice());
		resultImpl.setCorrect(getCorrect());
		resultImpl.setScore(getScore());

		resultImpl.resetOriginalValues();

		return resultImpl;
	}

	public int compareTo(Result result) {
		long primaryKey = result.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		Result result = null;

		try {
			result = (Result)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = result.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
	}

	@Override
	public CacheModel<Result> toCacheModel() {
		ResultCacheModel resultCacheModel = new ResultCacheModel();

		resultCacheModel.resultId = getResultId();

		resultCacheModel.quizId = getQuizId();

		resultCacheModel.userId = getUserId();

		resultCacheModel.questionId = getQuestionId();

		resultCacheModel.userName = getUserName();

		String userName = resultCacheModel.userName;

		if ((userName != null) && (userName.length() == 0)) {
			resultCacheModel.userName = null;
		}

		resultCacheModel.userChoice = getUserChoice();

		String userChoice = resultCacheModel.userChoice;

		if ((userChoice != null) && (userChoice.length() == 0)) {
			resultCacheModel.userChoice = null;
		}

		resultCacheModel.correct = getCorrect();

		String correct = resultCacheModel.correct;

		if ((correct != null) && (correct.length() == 0)) {
			resultCacheModel.correct = null;
		}

		resultCacheModel.score = getScore();

		return resultCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(17);

		sb.append("{resultId=");
		sb.append(getResultId());
		sb.append(", quizId=");
		sb.append(getQuizId());
		sb.append(", userId=");
		sb.append(getUserId());
		sb.append(", questionId=");
		sb.append(getQuestionId());
		sb.append(", userName=");
		sb.append(getUserName());
		sb.append(", userChoice=");
		sb.append(getUserChoice());
		sb.append(", correct=");
		sb.append(getCorrect());
		sb.append(", score=");
		sb.append(getScore());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(28);

		sb.append("<model><model-name>");
		sb.append("com.swt.mto.thithu.model.Result");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>resultId</column-name><column-value><![CDATA[");
		sb.append(getResultId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>quizId</column-name><column-value><![CDATA[");
		sb.append(getQuizId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userId</column-name><column-value><![CDATA[");
		sb.append(getUserId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>questionId</column-name><column-value><![CDATA[");
		sb.append(getQuestionId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userName</column-name><column-value><![CDATA[");
		sb.append(getUserName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userChoice</column-name><column-value><![CDATA[");
		sb.append(getUserChoice());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>correct</column-name><column-value><![CDATA[");
		sb.append(getCorrect());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>score</column-name><column-value><![CDATA[");
		sb.append(getScore());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = Result.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			Result.class
		};
	private long _resultId;
	private long _quizId;
	private long _userId;
	private String _userUuid;
	private long _questionId;
	private String _userName;
	private String _userChoice;
	private String _correct;
	private int _score;
	private Result _escapedModelProxy;
}